package com.erhirent.view;

import java.util.List;

import com.erhairent.tools.InputTools;
import com.erhirent.bean.Car;

public class ModView extends View {

	@Override
	public View showView() {
		// 可修改的车辆 可借
		List<Car> list1 = mcar.queryChange();
		if (list1.size() != 0) {
			System.out.println("---------------------------------------------");
			System.out.println("汽车ID\t" + "汽车名称\t" + "备注\t" + "品牌\t" + "类型\t" + "单价\t" + "是否可租");

			for (Car car : list1) {
				System.out.print(car.getcarId() + "\t");
				System.out.print(car.getcarName() + "\t");
				System.out.print(car.getcarRemark() + "\t");
				System.out.print(car.getbrandName() + "\t");
				System.out.print(car.gettypeName() + "\t");
				System.out.print(car.getcarPrice() + "/天\t");
				System.out.println(car.getcarIsrent() + "\t");
			}
			System.out.println("---------------------------------------------");
		} else {
			System.out.println("查询失败");
			return mView;
		}

		System.out.println("输入你要修改的汽车编号:");
		int num = InputTools.nextInt();
		List<Car> list2 = mcar.queryChange(num);
		if (list2.size() != 0) {
			System.out.println("---------------------------------------------");
			System.out.println("汽车ID\t" + "汽车名称\t" + "备注\t" + "品牌\t" + "类型\t" + "单价\t" + "是否可租");

			for (Car car : list2) {
				System.out.print(car.getcarId() + "\t");
				System.out.print(car.getcarName() + "\t");
				System.out.print(car.getcarRemark() + "\t");
				System.out.print(car.getbrandName() + "\t");
				System.out.print(car.gettypeName() + "\t");
				System.out.print(car.getcarPrice() + "/天\t");
				System.out.println(car.getcarIsrent() + "\t");
			}
			System.out.println("---------------------------------------------");
		} else {
			System.out.println("查询失败");
			return mView;
		}

		boolean iscon = true;
		for (; iscon;) {
			System.out.println("请输入你要修改的内容编号:");
			System.out.println("1.租赁价格   2.上架下架");
			int m = InputTools.nextInt();
			if (m == 1) {
				System.out.println("请输入新的租赁价格:");
				double pri = InputTools.nextDouble();
				if (mcar.changeCarPrice(pri, num)) {
					System.out.println("修改成功");
				} else {
					System.out.println("修改失败");
				}

			} else if (m == 2) {
				System.out.println("请选择上架或者下架:");
				System.out.println("1.上架   2.下架");
				int is = InputTools.nextInt();
				String putaway;
				if (is == 1) {
					putaway = "上架";
				} else {
					putaway = "下架";
				}

				if (mcar.changeCarputaway(putaway, num)) {
					System.out.println("修改成功");
					List<Car> list3 = mcar.queryChange(num);
					if (list3.size() != 0) {
						System.out.println("---------------------------------------------");
						System.out.println("汽车ID\t" + "汽车名称\t" + "备注\t" + "品牌\t" + "类型\t" + "单价\t" + "是否可租");

						for (Car car : list2) {
							System.out.print(car.getcarId() + "\t");
							System.out.print(car.getcarName() + "\t");
							System.out.print(car.getcarRemark() + "\t");
							System.out.print(car.getbrandName() + "\t");
							System.out.print(car.gettypeName() + "\t");
							System.out.print(car.getcarPrice() + "/天\t");
							System.out.println(car.getcarIsrent() + "\t");
						}
						System.out.println("---------------------------------------------");
					} else {
						System.out.println("查询失败");
					}

					iscon = false;
				} else {
					System.out.println("修改失败");
				}
			} else {
				System.out.println("输入不存在,重新输入:");
				continue;
			}
		}

		return mView;
	}

}
